<%@ taglib uri="/WEB-INF/vectrics.tld" prefix="vectrics" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<%@ page import="org.vectrics.user.Person" %>
<%@ page import="org.vectrics.hibernate.*" %>
<%@ page import="java.util.*" %>
<%@page import="org.vectrics.company.CompanyPerson"%>
<%@page import="org.vectrics.recruiter.RecruitServiceLocator"%>
<%@page import="org.vectrics.employee.Employee"%>

<%
	String userId = request.getParameter("userId");
	if (userId == null) {
		userId = request.getParameter("id");
	}
	if (userId == null) {
		userId = (String)request.getSession(true).getAttribute("userId");
	}
	
	String skillsEntryLink = request.getContextPath() + "/admin/jobs/candidate/index.do?id=" + userId;	
	
	if ((userId == null) || (userId.trim().length() == 0)) {
		userId = (String)request.getAttribute("userId");
	}
	if ((userId == null) || (userId.trim().length() == 0)) {
		userId = (String)request.getSession(true).getAttribute("userId");
	}
	if ((userId == null) || (userId.trim().length() == 0)) {
		userId = request.getParameter("id");
	}
	if ((userId == null) || (userId.trim().length() == 0)) {
		userId = request.getParameter("personId");
	}
	if ((userId == null) || (userId.trim().length() == 0)) {
		userId = (String)request.getAttribute("personId");
	}
	if ((userId != null) && (userId.equals("current"))) {
		userId = ThreadProperties.getPerson().getId().toString();
	}
	String personId = userId;
	if ((userId == null) || (userId.trim().length() == 0)) {
		throw new RuntimeException("User ID is blank or null");
	}
	
	boolean userCanChangePassword = ThreadProperties.getPerson().hasPrivilege("user.password.edit", ThreadProperties.getDomain());

	if (ThreadProperties.getPerson().getId().equals(new Long(personId))) {
		userCanChangePassword = true;
	}

	Date now = new Date();
	String candidateReportUrl = "/hrs-intranet/report/admin/candidate.pdf?report=candidate&personId="
			+ personId +
			"&time=" + now.getTime();
	
    String companyId = ThreadProperties.getDomain()
                              .getPrimaryCompany().getId().toString();
	
    boolean isEmployee;
    if(request.getAttribute("isEmployee")!=null){
    	isEmployee = (Boolean)request.getAttribute("isEmployee");
    }
    else{
        // Busco el empleado de la compania.
        Employee employee =  RecruitServiceLocator.getCompanyService().findEmployee(new Long(personId), new Long(companyId));
        isEmployee = (employee != null);
    }
	
	
%>

<table>
	<tr>
		<td>
			<vectrics:userSummary personId="<%=userId%>" compact="true"/>
			<br>
			<vectrics:userEvaluationList userId="<%=userId%>" />
		</td>
		<td valign="top" align="right">
			<table cellpadding="0" cellspacing="0">
				<tr>
					<td>
						<%if(isEmployee) { %>
							<form action="/hrs-intranet/admin/user/eval/newEval.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton elementId="eval.new.btn" code="button.param" phraseCode="button.eval.new" value="submit" name="submit"
									permission="manage_employees_items"/>
							</form>
						<%} else { %>
							<form action="/hrs-intranet/admin/user/eval/newEval.do" method="POST">
								<input type="hidden" name="userId" value="<%=userId%>">
								<vectrics:formButton elementId="eval.new.btn" code="button.param" phraseCode="button.eval.new" value="submit" name="submit"
									permission="manage_candidate_items"/>
							</form>
						<%}%>
					</td>
				</tr>
				<tr>
					<td>
						<form action="/hrs-intranet/admin/user/view.do" method="POST">
							<input type="hidden" name="userId" value="<%=userId%>">
							<vectrics:formButton elementId="person.info.btn" code="button.param" phraseCode="button.candidate.view.person" value="submit" name="submit"/>
						</form>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
